import geom.*;

import java.util.ArrayList;
import java.util.Iterator;

import processing.candy.SVG;
import processing.core.PApplet;
import tree.AbsorbtionBranch;


public class TreeGrowV2 extends PApplet{
	static public void main(String args[]) {
		PApplet.main(new String[] { 

			//"--present",
			"TreeGrowV2" 
		});
	}
	ArrayList<AbsorbtionBranch> branches;
	public void setup(){
		size(1440, 900);
		smooth();
		frameRate(50);
		background(255);
		branches = new ArrayList<AbsorbtionBranch>();
	}
	
	public void draw(){
		pushMatrix();
		translate(0, 450);
		scale(1);
		background(255);
		stroke(150, 0, 0, 150);
		line(-1000, 0, 1000, 0);
		stroke(0, 150, 0, 150);
		line(0, -1000, 0, 1000);
		Iterator<AbsorbtionBranch> it = branches.iterator();
		while(it.hasNext()){
			AbsorbtionBranch b = it.next();
			b.absorb(b.branchVolume() / 10f);
			b.grow();
			b.draw(this);
		}
		popMatrix();
	}
	
	public void keyPressed(){
		if(key == 'c'){
			float x = random(1440);
			float y = random(120);
			branches.clear();
			branches.add(new AbsorbtionBranch(null, null, new PolarVector(0, 0, 1), 2));
		}
	}
}
